﻿using DataHandle;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace DataControll
{
    public class RemoteLog
    {
        static KcpSocket kcpSocket;
        public static void OpenLog(int Port)
        {
            KcpDataControll.Instance.OpenServer(Port);
            Application.logMessageReceived += Log;
        }
        public static void SetTarget(string ip, int port)
        {
            kcpSocket = KcpDataControll.Instance.Connection(ip, port);
            kcpSocket.Keep = true;
        }
        public static void CloseLog()
        {
            Application.logMessageReceived -= Log;
        }
        static void Log(string condition, string stackTrace, LogType type)
        {
            if(kcpSocket!=null)
            {
                LogData log = new LogData();
                log.condition = condition;
                log.stackTrace = stackTrace;
                log.type = type;
                kcpSocket.SendJson((UInt16)MsgCmd.Log,JsonUtility.ToJson(log), MessageType.Def);
            }
        }
    }
}
